package com.yanqu.road.server.manager.group.service;

import com.google.protobuf.AbstractMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.command.ICrossServiceCommand;
import com.yanqu.road.server.manager.group.GroupChatMgr;
import com.yanqu.road.server.manager.player.WorldMessageMgr;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manger.ServerGroupMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.concurrent.CompletableFuture;


public class GetGroupChatListByUserIdCmdService implements ICrossServiceCommand {
    @Override
    public CompletableFuture<AbstractMessage.Builder<?>> execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        CompletableFuture<AbstractMessage.Builder<?>> promise = new CompletableFuture<>();

        int groupId = ServerGroupMgr.getGroupIdByServerId(request.getRawServerId());
        long userId = request.getSenderId();
        WorldMessageProto.WorldMessageListMsg.Builder messageList = GroupChatMgr.getChatListMsg(groupId);
        if (null == messageList) {
            messageList = WorldMessageProto.WorldMessageListMsg.newBuilder();
        }
        WorldMessageProto.WorldMessageListMsg.Builder respMsg = WorldMessageProto.WorldMessageListMsg.newBuilder();
        for (WorldMessageProto.WorldMessageTempMsg chatMsg : messageList.getDataListList()) {
            if (chatMsg.getUserId() != userId){
                continue;
            }
            if (chatMsg.getContentType() == 2){
                continue;
            }
            respMsg.addDataList(chatMsg);
        }
        promise.complete(respMsg);
        return promise;
    }
}
